package com.micro.school.edu.controller;

import java.util.List;

import com.micro.school.common.core.context.SecurityContextHolder;
import com.micro.school.common.core.utils.poi.ExcelUtil;
import com.micro.school.common.core.web.controller.BaseController;
import com.micro.school.common.core.web.domain.AjaxResult;
import com.micro.school.common.core.web.page.TableDataInfo;
import com.micro.school.common.log.annotation.Log;
import com.micro.school.common.log.enums.BusinessType;
import com.micro.school.common.security.annotation.RequiresPermissions;
import com.micro.school.common.security.utils.SecurityUtils;
import com.micro.school.edu.domain.vo.SchoolFeeYearVo;
import com.micro.school.edu.domain.vo.SchoolGradeVo;
import com.micro.school.edu.service.ISchoolGradeService;
import com.micro.school.system.api.domain.vo.SchoolGradeVos;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 学校年级Controller
 *
 * @author rakic
 * @date 2025-08-07
 */
@RestController
@RequestMapping("/grade")
public class SchoolGradeController extends BaseController
{
    @Autowired
    private ISchoolGradeService schoolGradeService;

    /**
     * 查询学校年级列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SchoolGradeVo schoolGradeVo)
    {
        startPage();
        List<SchoolGradeVo> list = schoolGradeService.selectSchoolGradeList(schoolGradeVo);
        return getDataTable(list);
    }
    /**
     * 查询列表不分页
     */
    @GetMapping("/getSchoolGradeList")
    public  AjaxResult getSchoolGradeList(SchoolGradeVo schoolGradeVo)
    {
        List<SchoolGradeVo> list = schoolGradeService.selectSchoolGradeList(schoolGradeVo);
        return success(list);
    }

    /**
     * 查询列表不分页
     */
    @PostMapping("/getSchoolGradeLists")
    public  AjaxResult getSchoolGradeLists(@RequestBody SchoolGradeVos schoolGradeVos)
    {
        List<SchoolGradeVos> list = schoolGradeService.selectSchoolGradeLists(schoolGradeVos);
        return success(list);
    }

    /**
     * 导出学校年级列表
     */
    @Log(title = "学校年级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchoolGradeVo schoolGradeVo)
    {
        List<SchoolGradeVo> list = schoolGradeService.selectSchoolGradeList(schoolGradeVo);
        ExcelUtil<SchoolGradeVo> util = new ExcelUtil<SchoolGradeVo>(SchoolGradeVo.class);
        util.exportExcel(response, list, "学校年级数据");
    }

    /**
     * 获取学校年级详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(schoolGradeService.selectSchoolGradeById(id));
    }

    /**
     * 获取学校年级详细信息
     */
    @GetMapping(value = "/feign/{id}")
    public AjaxResult getFeignInfo(@PathVariable("id") Long id)
    {
        return success(schoolGradeService.selectSchoolGradeByIds(id));
    }

    /**
     * 新增学校年级
     */
    @Log(title = "学校年级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchoolGradeVo schoolGradeVo)
    {
        return schoolGradeService.insertSchoolGrade(schoolGradeVo);
    }

    /**
     * 修改学校年级
     */
    @Log(title = "学校年级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchoolGradeVo schoolGradeVo)
    {
        return toAjax(schoolGradeService.updateSchoolGrade(schoolGradeVo));
    }

    /**
     * 删除学校年级
     */
    @Log(title = "学校年级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        SchoolGradeVo schoolGradeVo=new SchoolGradeVo();
        schoolGradeVo=schoolGradeService.selectSchoolGradeById(ids.get(0));
        schoolGradeVo.setDeleteFlag("1");
        return toAjax(schoolGradeService.updateSchoolGrade(schoolGradeVo));
    }
//    public AjaxResult remove(@PathVariable List<Long> ids)
//    {
//        return toAjax(schoolGradeService.deleteSchoolGradeByIds(ids));
//    }


}
